home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / gcc / gcc261a.zoo / info / libg++.info-3 < prev    next >
Encoding:
GNU Info File  |  1994-11-07  |  49.1 KB  |  1,398 lines

  1. This is Info file libg++.info, produced by Makeinfo-1.55 from the input
  2. file ./libg++.texi.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Libg++: (libg++).             The g++ class library.
  6. END-INFO-DIR-ENTRY
  7.  
  8.    This file documents the features and implementation of The GNU C++
  9. library
  10.  
  11.    Copyright (C) 1988, 1991, 1992 Free Software Foundation, Inc.
  12.  
  13.    Permission is granted to make and distribute verbatim copies of this
  14. manual provided the copyright notice and this permission notice are
  15. preserved on all copies.
  16.  
  17.    Permission is granted to copy and distribute modified versions of
  18. this manual under the conditions for verbatim copying, provided also
  19. that the section entitled "GNU Library General Public License" is
  20. included exactly as in the original, and provided that the entire
  21. resulting derived work is distributed under the terms of a permission
  22. notice identical to this one.
  23.  
  24.    Permission is granted to copy and distribute translations of this
  25. manual into another language, under the above conditions for modified
  26. versions, except that the section entitled "GNU Library General Public
  27. License" and this permission notice may be included in translations
  28. approved by the Free Software Foundation instead of in the original
  29. English.
  30.  
  31. File: libg++.info,  Node: String,  Next: Integer,  Prev: AllocRing,  Up: Top
  32.  
  33. The String class
  34. ****************
  35.  
  36.    The `String' class is designed to extend GNU C++ to support string
  37. processing capabilities similar to those in languages like Awk.  The
  38. class provides facilities that ought to be convenient and efficient
  39. enough to be useful replacements for `char*' based processing via the C
  40. string library (i.e., `strcpy, strcmp,' etc.) in many applications.
  41. Many details about String representations are described in the
  42. Representation section.
  43.  
  44.    A separate `SubString' class supports substring extraction and
  45. modification operations. This is implemented in a way that user
  46. programs never directly construct or represent substrings, which are
  47. only used indirectly via String operations.
  48.  
  49.    Another separate class, `Regex' is also used indirectly via String
  50. operations in support of regular expression searching, matching, and the
  51. like.  The Regex class is based entirely on the GNU Emacs regex
  52. functions.  *Note Syntax of Regular Expressions: (emacs.info)Regexps,
  53. for a full explanation of regular expression syntax.  (For
  54. implementation details, see the internal documentation in files
  55. `regex.h' and `regex.c'.)
  56.  
  57. Constructors
  58. ============
  59.  
  60.    Strings are initialized and assigned as in the following examples:
  61.  
  62. `String x;  String y = 0; String z = "";'
  63.      Set x, y, and z to the nil string. Note that either 0 or "" may
  64.      always be used to refer to the nil string.
  65.  
  66. `String x = "Hello"; String y("Hello");'
  67.      Set x and y to a copy of the string "Hello".
  68.  
  69. `String x = 'A'; String y('A');'
  70.      Set x and y to the string value "A"
  71.  
  72. `String u = x; String v(x);'
  73.      Set u and v to the same string as String x
  74.  
  75. `String u = x.at(1,4); String v(x.at(1,4));'
  76.      Set u and v to the length 4 substring of x starting at position 1
  77.      (counting indexes from 0).
  78.  
  79. `String x("abc", 2);'
  80.      Sets x to "ab", i.e., the first 2 characters of "abc".
  81.  
  82. `String x = dec(20);'
  83.      Sets x to "20". As here, Strings may be initialized or assigned
  84.      the results of any `char*' function.
  85.  
  86.    There are no directly accessible forms for declaring SubString
  87. variables.
  88.  
  89.    The declaration `Regex r("[a-zA-Z_][a-zA-Z0-9_]*");' creates a
  90. compiled regular expression suitable for use in String operations
  91. described below. (In this case, one that matches any C++ identifier).
  92. The first argument may also be a String.  Be careful in distinguishing
  93. the role of backslashes in quoted GNU C++ char* constants versus those
  94. in Regexes. For example, a Regex that matches either one or more tabs
  95. or all strings beginning with "ba" and ending with any number of
  96. occurrences of "na" could be declared as `Regex r =
  97. "\\(\t+\\)\\|\\(ba\\(na\\)*\\)"' Note that only one backslash is needed
  98. to signify the tab, but two are needed for the parenthesization and
  99. virgule, since the GNU C++ lexical analyzer decodes and strips
  100. backslashes before they are seen by Regex.
  101.  
  102.    There are three additional optional arguments to the Regex
  103. constructor that are less commonly useful:
  104.  
  105. `fast (default 0)'
  106.      `fast' may be set to true (1) if the Regex should be
  107.      "fast-compiled". This causes an additional compilation step that
  108.      is generally worthwhile if the Regex will be used many times.
  109.  
  110. `bufsize (default max(40, length of the string))'
  111.      This is an estimate of the size of the internal compiled
  112.      expression. Set it to a larger value if you know that the
  113.      expression will require a lot of space. If you do not know, do not
  114.      worry: realloc is used if necessary.
  115.  
  116. `transtable (default none == 0)'
  117.      The address of a byte translation table (a char[256]) that
  118.      translates each character before matching.
  119.  
  120.    As a convenience, several Regexes are predefined and usable in any
  121. program. Here are their declarations from `String.h'.
  122.  
  123.      extern Regex RXwhite;      // = "[ \n\t]+"
  124.      extern Regex RXint;        // = "-?[0-9]+"
  125.      extern Regex RXdouble;     // = "-?\\(\\([0-9]+\\.[0-9]*\\)\\|
  126.                                 //    \\([0-9]+\\)\\|
  127.                                 //    \\(\\.[0-9]+\\)\\)
  128.                                 //    \\([eE][---+]?[0-9]+\\)?"
  129.      extern Regex RXalpha;      // = "[A-Za-z]+"
  130.      extern Regex RXlowercase;  // = "[a-z]+"
  131.      extern Regex RXuppercase;  // = "[A-Z]+"
  132.      extern Regex RXalphanum;   // = "[0-9A-Za-z]+"
  133.      extern Regex RXidentifier; // = "[A-Za-z_][A-Za-z0-9_]*"
  134.  
  135. Examples
  136. ========
  137.  
  138.    Most `String' class capabilities are best shown via example.  The
  139. examples below use the following declarations.
  140.  
  141.          String x = "Hello";
  142.          String y = "world";
  143.          String n = "123";
  144.          String z;
  145.          char*  s = ",";
  146.          String lft, mid, rgt;
  147.          Regex  r = "e[a-z]*o";
  148.          Regex  r2("/[a-z]*/");
  149.          char   c;
  150.          int    i, pos, len;
  151.          double f;
  152.          String words[10];
  153.          words[0] = "a";
  154.          words[1] = "b";
  155.          words[2] = "c";
  156.  
  157. Comparing, Searching and Matching
  158. =================================
  159.  
  160.    The usual lexicographic relational operators (`==, !=, <, <=, >, >=')
  161. are defined. A functional form `compare(String, String)' is also
  162. provided, as is `fcompare(String, String)', which compares Strings
  163. without regard for upper vs. lower case.
  164.  
  165.    All other matching and searching operations are based on some form
  166. of the (non-public) `match' and `search' functions.  `match' and
  167. `search' differ in that `match' attempts to match only at the given
  168. starting position, while `search' starts at the position, and then
  169. proceeds left or right looking for a match.  As seen in the following
  170. examples, the second optional `startpos' argument to functions using
  171. `match' and `search' specifies the starting position of the search: If
  172. non-negative, it results in a left-to-right search starting at position
  173. `startpos', and if negative, a right-to-left search starting at
  174. position `x.length() + startpos'. In all cases, the index returned is
  175. that of the beginning of the match, or -1 if there is no match.
  176.  
  177.    Three String functions serve as front ends to `search' and `match'.
  178. `index' performs a search, returning the index, `matches' performs a
  179. match, returning nonzero (actually, the length of the match) on success,
  180. and `contains' is a boolean function performing either a search or
  181. match, depending on whether an index argument is provided:
  182.  
  183. `x.index("lo")'
  184.      returns the zero-based index of the leftmost occurrence of
  185.      substring "lo" (3, in this case).  The argument may be a String,
  186.      SubString, char, char*, or Regex.
  187.  
  188. `x.index("l", 2)'
  189.      returns the index of the first of the leftmost occurrence of "l"
  190.      found starting the search at position x[2], or 2 in this case.
  191.  
  192. `x.index("l", -1)'
  193.      returns the index of the rightmost occurrence of "l", or 3 here.
  194.  
  195. `x.index("l", -3)'
  196.      returns the index of the rightmost occurrence of "l" found by
  197.      starting the search at the 3rd to the last position of x,
  198.      returning 2 in this case.
  199.  
  200. `pos = r.search("leo", 3, len, 0)'
  201.      returns the index of r in the `char*' string of length 3, starting
  202.      at position 0, also placing the  length of the match in reference
  203.      parameter len.
  204.  
  205. `x.contains("He")'
  206.      returns nonzero if the String x contains the substring "He". The
  207.      argument may be a String, SubString, char, char*, or Regex.
  208.  
  209. `x.contains("el", 1)'
  210.      returns nonzero if x contains the substring "el" at position 1.
  211.      As in this example, the second argument to `contains', if present,
  212.      means to match the substring only at that position, and not to
  213.      search elsewhere in the string.
  214.  
  215. `x.contains(RXwhite);'
  216.      returns nonzero if x contains any whitespace (space, tab, or
  217.      newline). Recall that `RXwhite' is a global whitespace Regex.
  218.  
  219. `x.matches("lo", 3)'
  220.      returns nonzero if x starting at position 3 exactly matches "lo",
  221.      with no trailing characters (as it does in this example).
  222.  
  223. `x.matches(r)'
  224.      returns nonzero if String x as a whole matches Regex r.
  225.  
  226. `int f = x.freq("l")'
  227.      returns the number of distinct, nonoverlapping matches to the
  228.      argument (2 in this case).
  229.  
  230. Substring extraction
  231. ====================
  232.  
  233.    Substrings may be extracted via the `at', `before', `through',
  234. `from', and `after' functions.  These behave as either lvalues or
  235. rvalues.
  236.  
  237. `z = x.at(2, 3)'
  238.      sets String z to be equal to the length 3 substring of String x
  239.      starting at zero-based position 2, setting z to "llo" in this
  240.      case. A nil String is returned if the arguments don't make sense.
  241.  
  242. `x.at(2, 2) = "r"'
  243.      Sets what was in positions 2 to 3 of x to "r", setting x to "Hero"
  244.      in this case. As indicated here, SubString assignments may be of
  245.      different lengths.
  246.  
  247. `x.at("He") = "je";'
  248.      x("He") is the substring of x that matches the first occurrence of
  249.      it's argument. The substitution sets x to "jello". If "He" did not
  250.      occur, the substring would be nil, and the assignment would have
  251.      no effect.
  252.  
  253. `x.at("l", -1) = "i";'
  254.      replaces the rightmost occurrence of "l" with "i", setting x to
  255.      "Helio".
  256.  
  257. `z = x.at(r)'
  258.      sets String z to the first match in x of Regex r, or "ello" in this
  259.      case. A nil String is returned if there is no match.
  260.  
  261. `z = x.before("o")'
  262.      sets z to the part of x to the left of the first occurrence of
  263.      "o", or "Hell" in this case. The argument may also be a String,
  264.      SubString, or Regex.  (If there is no match, z is set to "".)
  265.  
  266. `x.before("ll") = "Bri";'
  267.      sets the part of x to the left of "ll" to "Bri", setting x to
  268.      "Brillo".
  269.  
  270. `z = x.before(2)'
  271.      sets z to the part of x to the left of x[2], or "He" in this case.
  272.  
  273. `z = x.after("Hel")'
  274.      sets z to the part of x to the right of "Hel", or "lo" in this
  275.      case.
  276.  
  277. `z = x.through("el")'
  278.      sets z to the part of x up and including "el", or "Hel" in this
  279.      case.
  280.  
  281. `z = x.from("el")'
  282.      sets z to the part of x from "el" to the end, or "ello" in this
  283.      case.
  284.  
  285. `x.after("Hel") = "p";'
  286.      sets x to "Help";
  287.  
  288. `z = x.after(3)'
  289.      sets z to the part of x to the right of x[3] or "o" in this case.
  290.  
  291. `z = "  ab c"; z = z.after(RXwhite)'
  292.      sets z to the part of its old string to the right of the first
  293.      group of whitespace, setting z to "ab c"; Use gsub(below) to strip
  294.      out multiple occurrences of whitespace or any pattern.
  295.  
  296. `x[0] = 'J';'
  297.      sets the first element of x to 'J'. x[i] returns a reference to
  298.      the ith element of x, or triggers an error if i is out of range.
  299.  
  300. `common_prefix(x, "Help")'
  301.      returns the String containing the common prefix of the two Strings
  302.      or "Hel" in this case.
  303.  
  304. `common_suffix(x, "to")'
  305.      returns the String containing the common suffix of the two Strings
  306.      or "o" in this case.
  307.  
  308. Concatenation
  309. =============
  310.  
  311. `z = x + s + ' ' + y.at("w") + y.after("w") + ".";'
  312.      sets z to "Hello, world."
  313.  
  314. `x += y;'
  315.      sets x to "Helloworld"
  316.  
  317. `cat(x, y, z)'
  318.      A faster way to say z = x + y.
  319.  
  320. `cat(z, y, x, x)'
  321.      Double concatenation; A faster way to say x = z + y + x.
  322.  
  323. `y.prepend(x);'
  324.      A faster way to say y = x + y.
  325.  
  326. `z = replicate(x, 3);'
  327.      sets z to "HelloHelloHello".
  328.  
  329. `z = join(words, 3, "/")'
  330.      sets z to the concatenation of the first 3 Strings in String array
  331.      words, each separated by "/", setting z to "a/b/c" in this case.
  332.      The last argument may be "" or 0, indicating no separation.
  333.  
  334. Other manipulations
  335. ===================
  336.  
  337. `z = "this string has five words"; i = split(z, words, 10, RXwhite);'
  338.      sets up to 10 elements of String array words to the parts of z
  339.      separated by whitespace, and returns the number of parts actually
  340.      encountered (5 in this case). Here, words[0] = "this", words[1] =
  341.      "string", etc.  The last argument may be any of the usual.  If
  342.      there is no match, all of z ends up in words[0]. The words array
  343.      is *not* dynamically created by split.
  344.  
  345. `int nmatches x.gsub("l","ll")'
  346.      substitutes all original occurrences of "l" with "ll", setting x
  347.      to "Hellllo". The first argument may be any of the usual,
  348.      including Regex.  If the second argument is "" or 0, all
  349.      occurrences are deleted. gsub returns the number of matches that
  350.      were replaced.
  351.  
  352. `z = x + y;  z.del("loworl");'
  353.      deletes the leftmost occurrence of "loworl" in z, setting z to
  354.      "Held".
  355.  
  356. `z = reverse(x)'
  357.      sets z to the reverse of x, or "olleH".
  358.  
  359. `z = upcase(x)'
  360.      sets z to x, with all letters set to uppercase, setting z to
  361.      "HELLO"
  362.  
  363. `z = downcase(x)'
  364.      sets z to x, with all letters set to lowercase, setting z to
  365.      "hello"
  366.  
  367. `z = capitalize(x)'
  368.      sets z to x, with the first letter of each word set to uppercase,
  369.      and all others to lowercase, setting z to "Hello"
  370.  
  371. `x.reverse(), x.upcase(), x.downcase(), x.capitalize()'
  372.      in-place, self-modifying versions of the above.
  373.  
  374. Reading, Writing and Conversion
  375. ===============================
  376.  
  377. `cout << x'
  378.      writes out x.
  379.  
  380. `cout << x.at(2, 3)'
  381.      writes out the substring "llo".
  382.  
  383. `cin >> x'
  384.      reads a whitespace-bounded string into x.
  385.  
  386. `x.length()'
  387.      returns the length of String x (5, in this case).
  388.  
  389. `s = (const char*)x'
  390.      can be used to extract the `char*' char array. This coercion is
  391.      useful for sending a String as an argument to any function
  392.      expecting a `const char*' argument (like `atoi', and
  393.      `File::open'). This operator must be used with care, since the
  394.      conversion returns a pointer to `String' internals without copying
  395.      the characters: The resulting `(char*)' is only valid until the
  396.      next String operation,  and you must not modify it.  (The
  397.      conversion is defined to return a const value so that GNU C++ will
  398.      produce warning and/or error messages if changes are attempted.)
  399.  
  400. File: libg++.info,  Node: Integer,  Next: Rational,  Prev: String,  Up: Top
  401.  
  402. The Integer class.
  403. ******************
  404.  
  405.    The `Integer' class provides multiple precision integer arithmetic
  406. facilities. Some representation details are discussed in the
  407. Representation section.
  408.  
  409.    `Integers' may be up to `b * ((1 << b) - 1)' bits long, where `b' is
  410. the number of bits per short (typically 1048560 bits when `b = 16').
  411. The implementation assumes that a `long' is at least twice as long as a
  412. `short'. This assumption hides beneath almost all primitive operations,
  413. and would be very difficult to change. It also relies on correct
  414. behavior of *unsigned* arithmetic operations.
  415.  
  416.    Some of the arithmetic algorithms are very loosely based on those
  417. provided in the MIT Scheme `bignum.c' release, which is Copyright (c)
  418. 1987 Massachusetts Institute of Technology. Their use here falls within
  419. the provisions described in the Scheme release.
  420.  
  421.    Integers may be constructed in the following ways:
  422. `Integer x;'
  423.      Declares an uninitialized Integer.
  424.  
  425. `Integer x = 2; Integer y(2);'
  426.      Set x and y to the Integer value 2;
  427.  
  428. `Integer u(x); Integer v = x;'
  429.      Set u and v to the same value as x.
  430.  
  431.  - Method: long Integer::as_long() const
  432.      Used to coerce an `Integer' back into longs via the `long'
  433.      coercion operator. If the Integer cannot fit into a long, this
  434.      returns MINLONG or MAXLONG (depending on the sign) where MINLONG
  435.      is the most negative, and MAXLONG is the most positive
  436.      representable long.
  437.  
  438.  - Method: int Integer::fits_in_long() const
  439.      Returns true iff the `Integer' is `< MAXLONG' and `> MINLONG'.
  440.  
  441.  - Method: double Integer::as_double() const
  442.      Coerce the `Integer' to a `double', with potential loss of
  443.      precision.  `+/-HUGE' is returned if the Integer cannot fit into a
  444.      double.
  445.  
  446.  - Method: int Integer::fits_in_double() const
  447.      Returns true iff the `Integer' can fit into a double.
  448.  
  449.    All of the usual arithmetic operators are provided (`+, -, *, /, %,
  450. +=, ++, -=, --, *=, /=, %=, ==, !=, <, <=, >, >=').  All operators
  451. support special versions for mixed arguments of Integers and regular
  452. C++ longs in order to avoid useless coercions, as well as to allow
  453. automatic promotion of shorts and ints to longs, so that they may be
  454. applied without additional Integer coercion operators.  The only
  455. operators that behave differently than the corresponding int or long
  456. operators are `++' and `--'.  Because C++ does not distinguish prefix
  457. from postfix application, these are declared as `void' operators, so
  458. that no confusion can result from applying them as postfix.  Thus, for
  459. Integers x and y, ` ++x; y = x; ' is correct, but ` y = ++x; ' and ` y
  460. = x++; ' are not.
  461.  
  462.    Bitwise operators (`~', `&', `|', `^', `<<', `>>', `&=', `|=', `^=',
  463. `<<=', `>>=') are also provided.  However, these operate on
  464. sign-magnitude, rather than two's complement representations. The sign
  465. of the result is arbitrarily taken as the sign of the first argument.
  466. For example, `Integer(-3) & Integer(5)' returns `Integer(-1)', not -3,
  467. as it would using two's complement. Also, `~', the complement operator,
  468. complements only those bits needed for the representation.  Bit
  469. operators are also provided in the BitSet and BitString classes. One of
  470. these classes should be used instead of Integers when the results of
  471. bit manipulations are not interpreted numerically.
  472.  
  473.    The following utility functions are also provided. (All arguments
  474. are Integers unless otherwise noted).
  475.  
  476.  - Function: void divide(const Integer& X, const Integer& Y, Integer&
  477.           Q, Integer& R)
  478.      Sets Q to the quotient and R to the remainder of X and Y.  (Q and
  479.      R are returned by reference).
  480.  
  481.  - Function: Integer pow(const Integer& X, const Integer& P)
  482.      Returns X raised to the power P.
  483.  
  484.  - Function: Integer Ipow(long X, long P)
  485.      Returns X raised to the power P.
  486.  
  487.  - Function: Integer gcd(const Integer& X, const Integer& P)
  488.      Returns the greatest common divisor of X and Y.
  489.  
  490.  - Function: Integer lcm(const Integer& X, const Integer& P)
  491.      Returns the least common multiple of X and Y.
  492.  
  493.  - Function: Integer abs(const Integer& X
  494.      Returns the absolute value of X.
  495.  
  496.  - Method: void Integer::negate()
  497.      Negates `this' in place.
  498.  
  499. `Integer sqr(x)'
  500.      returns x * x;
  501.  
  502. `Integer sqrt(x)'
  503.      returns the floor of the  square root of x.
  504.  
  505. `long lg(x);'
  506.      returns the floor of the base 2 logarithm of abs(x)
  507.  
  508. `int sign(x)'
  509.      returns -1 if x is negative, 0 if zero, else +1.  Using `if
  510.      (sign(x) == 0)' is a generally faster method of testing for zero
  511.      than using relational operators.
  512.  
  513. `int even(x)'
  514.      returns true if x is an even number
  515.  
  516. `int odd(x)'
  517.      returns true if x is an odd number.
  518.  
  519. `void setbit(Integer& x, long b)'
  520.      sets the b'th bit (counting right-to-left from zero) of x to 1.
  521.  
  522. `void clearbit(Integer& x, long b)'
  523.      sets the b'th bit of x to 0.
  524.  
  525. `int testbit(Integer x, long b)'
  526.      returns true if the b'th bit of x is 1.
  527.  
  528. `Integer atoI(char* asciinumber, int base = 10);'
  529.      converts the base base char* string into its Integer form.
  530.  
  531. `void Integer::printon(ostream& s, int base = 10, int width = 0);'
  532.      prints the ascii string value of `(*this)' as a base `base'
  533.      number, in field width at least `width'.
  534.  
  535. `ostream << x;'
  536.      prints x in base ten format.
  537.  
  538. `istream >> x;'
  539.      reads x as a base ten number.
  540.  
  541. `int compare(Integer x, Integer y)'
  542.      returns a negative number if x<y, zero if x==y, or positive if x>y.
  543.  
  544. `int ucompare(Integer x, Integer y)'
  545.      like compare, but performs unsigned comparison.
  546.  
  547. `add(x, y, z)'
  548.      A faster way to say z = x + y.
  549.  
  550. `sub(x, y, z)'
  551.      A faster way to say z = x - y.
  552.  
  553. `mul(x, y, z)'
  554.      A faster way to say z = x * y.
  555.  
  556. `div(x, y, z)'
  557.      A faster way to say z = x / y.
  558.  
  559. `mod(x, y, z)'
  560.      A faster way to say z = x % y.
  561.  
  562. `and(x, y, z)'
  563.      A faster way to say z = x & y.
  564.  
  565. `or(x, y, z)'
  566.      A faster way to say z = x | y.
  567.  
  568. `xor(x, y, z)'
  569.      A faster way to say z = x ^ y.
  570.  
  571. `lshift(x, y, z)'
  572.      A faster way to say z = x << y.
  573.  
  574. `rshift(x, y, z)'
  575.      A faster way to say z = x >> y.
  576.  
  577. `pow(x, y, z)'
  578.      A faster way to say z = pow(x, y).
  579.  
  580. `complement(x, z)'
  581.      A faster way to say z = ~x.
  582.  
  583. `negate(x, z)'
  584.      A faster way to say z = -x.
  585.  
  586. File: libg++.info,  Node: Rational,  Next: Complex,  Prev: Integer,  Up: Top
  587.  
  588. The Rational Class
  589. ******************
  590.  
  591.    Class `Rational' provides multiple precision rational number
  592. arithmetic. All rationals are maintained in simplest form (i.e., with
  593. the numerator and denominator relatively prime, and with the
  594. denominator strictly positive).  Rational arithmetic and relational
  595. operators are provided (`+, -, *, /, +=, -=, *=, /=, ==, !=, <, <=, >,
  596. >=').  Operations resulting in a rational number with zero denominator
  597. trigger an exception.
  598.  
  599.    Rationals may be constructed and used in the following ways:
  600.  
  601. `Rational x;'
  602.      Declares an uninitialized Rational.
  603.  
  604. `Rational x = 2; Rational y(2);'
  605.      Set x and y to the Rational value 2/1;
  606.  
  607. `Rational x(2, 3);'
  608.      Sets x to the Rational value 2/3;
  609.  
  610. `Rational x = 1.2;'
  611.      Sets x to a Rational value close to 1.2. Any double precision value
  612.      may be used to construct a Rational. The Rational will possess
  613.      exactly as much precision as the double. Double values that do not
  614.      have precise floating point equivalents (like 1.2) produce
  615.      similarly imprecise rational values.
  616.  
  617. `Rational x(Integer(123), Integer(4567));'
  618.      Sets x to the Rational value 123/4567.
  619.  
  620. `Rational u(x); Rational v = x;'
  621.      Set u and v to the same value as x.
  622.  
  623. `double(Rational x)'
  624.      A Rational may be coerced to a double with potential loss of
  625.      precision. +/-HUGE is returned if it will not fit.
  626.  
  627. `Rational abs(x)'
  628.      returns the absolute value of x.
  629.  
  630. `void x.negate()'
  631.      negates x.
  632.  
  633. `void x.invert()'
  634.      sets x to 1/x.
  635.  
  636. `int sign(x)'
  637.      returns 0 if x is zero, 1 if positive, and -1 if negative.
  638.  
  639. `Rational sqr(x)'
  640.      returns x * x.
  641.  
  642. `Rational pow(x, Integer y)'
  643.      returns x to the y power.
  644.  
  645. `Integer x.numerator()'
  646.      returns the numerator.
  647.  
  648. `Integer x.denominator()'
  649.      returns the denominator.
  650.  
  651. `Integer floor(x)'
  652.      returns the greatest Integer less than x.
  653.  
  654. `Integer ceil(x)'
  655.      returns the least Integer greater than x.
  656.  
  657. `Integer trunc(x)'
  658.      returns the Integer part of x.
  659.  
  660. `Integer round(x)'
  661.      returns the nearest Integer to x.
  662.  
  663. `int compare(x, y)'
  664.      returns a negative, zero, or positive number signifying whether x
  665.      is less than, equal to, or greater than y.
  666.  
  667. `ostream << x;'
  668.      prints x in the form num/den, or just num if the denominator is
  669.      one.
  670.  
  671. `istream >> x;'
  672.      reads x in the form num/den, or just num in which case the
  673.      denominator is set to one.
  674.  
  675. `add(x, y, z)'
  676.      A faster way to say z = x + y.
  677.  
  678. `sub(x, y, z)'
  679.      A faster way to say z = x - y.
  680.  
  681. `mul(x, y, z)'
  682.      A faster way to say z = x * y.
  683.  
  684. `div(x, y, z)'
  685.      A faster way to say z = x / y.
  686.  
  687. `pow(x, y, z)'
  688.      A faster way to say z = pow(x, y).
  689.  
  690. `negate(x, z)'
  691.      A faster way to say z = -x.
  692.  
  693. File: libg++.info,  Node: Complex,  Next: Fix,  Prev: Rational,  Up: Top
  694.  
  695. The Complex class.
  696. ******************
  697.  
  698.    Class `Complex' is implemented in a way similar to that described by
  699. Stroustrup. In keeping with libg++ conventions, the class is named
  700. `Complex', not `complex'.  Complex arithmetic and relational operators
  701. are provided (`+, -, *, /, +=, -=, *=, /=, ==, !=').  Attempted
  702. division by (0, 0) triggers an exception.
  703.  
  704.    Complex numbers may be constructed and used in the following ways:
  705.  
  706. `Complex x;'
  707.      Declares an uninitialized Complex.
  708.  
  709. `Complex x = 2; Complex y(2.0);'
  710.      Set x and y to the Complex value (2.0, 0.0);
  711.  
  712. `Complex x(2, 3);'
  713.      Sets x to the Complex value (2, 3);
  714.  
  715. `Complex u(x); Complex v = x;'
  716.      Set u and v to the same value as x.
  717.  
  718. `double real(Complex& x);'
  719.      returns the real part of x.
  720.  
  721. `double imag(Complex& x);'
  722.      returns the imaginary part of x.
  723.  
  724. `double abs(Complex& x);'
  725.      returns the magnitude of x.
  726.  
  727. `double norm(Complex& x);'
  728.      returns the square of the magnitude of x.
  729.  
  730. `double arg(Complex& x);'
  731.      returns the argument (amplitude) of x.
  732.  
  733. `Complex polar(double r, double t = 0.0);'
  734.      returns a Complex with abs of r and arg of t.
  735.  
  736. `Complex conj(Complex& x);'
  737.      returns the complex conjugate of x.
  738.  
  739. `Complex cos(Complex& x);'
  740.      returns the complex cosine of x.
  741.  
  742. `Complex sin(Complex& x);'
  743.      returns the complex sine of x.
  744.  
  745. `Complex cosh(Complex& x);'
  746.      returns the complex hyperbolic cosine of x.
  747.  
  748. `Complex sinh(Complex& x);'
  749.      returns the complex hyperbolic sine of x.
  750.  
  751. `Complex exp(Complex& x);'
  752.      returns the exponential of x.
  753.  
  754. `Complex log(Complex& x);'
  755.      returns the natural log of x.
  756.  
  757. `Complex pow(Complex& x, long p);'
  758.      returns x raised to the p power.
  759.  
  760. `Complex pow(Complex& x, Complex& p);'
  761.      returns x raised to the p power.
  762.  
  763. `Complex sqrt(Complex& x);'
  764.      returns the square root of x.
  765.  
  766. `ostream << x;'
  767.      prints x in the form (re, im).
  768.  
  769. `istream >> x;'
  770.      reads x in the form (re, im), or just (re) or re in which case the
  771.      imaginary part is set to zero.
  772.  
  773. File: libg++.info,  Node: Fix,  Next: Bit,  Prev: Complex,  Up: Top
  774.  
  775. Fixed precision numbers
  776. ***********************
  777.  
  778.    Classes `Fix16', `Fix24', `Fix32', and `Fix48' support operations on
  779. 16, 24, 32, or 48 bit quantities that are considered as real numbers in
  780. the range [-1, +1).  Such numbers are often encountered in digital
  781. signal processing applications. The classes may be be used in isolation
  782. or together.  Class `Fix32' operations are entirely self-contained.
  783. Class `Fix16' operations are self-contained except that the
  784. multiplication operation `Fix16 * Fix16' returns a `Fix32'. `Fix24' and
  785. `Fix48' are similarly related.
  786.  
  787.    The standard arithmetic and relational operations are supported
  788. (`=', `+', `-', `*', `/', `<<', `>>', `+=', `-=', `*=', `/=', `<<=',
  789. `>>=', `==', `!=', `<', `<=', `>', `>=').  All operations include
  790. provisions for special handling in cases where the result exceeds +/-
  791. 1.0. There are two cases that may be handled separately: "overflow"
  792. where the results of addition and subtraction operations go out of
  793. range, and all other "range errors" in which resulting values go
  794. off-scale (as with division operations, and assignment or
  795. initialization with off-scale values). In signal processing
  796. applications, it is often useful to handle these two cases differently.
  797. Handlers take one argument, a reference to the integer mantissa of the
  798. offending value, which may then be manipulated.  In cases of overflow,
  799. this value is the result of the (integer) arithmetic computation on the
  800. mantissa; in others it is a fully saturated (i.e., most positive or
  801. most negative) value. Handling may be reset to any of several provided
  802. functions or any other user-defined function via `set_overflow_handler'
  803. and `set_range_error_handler'. The provided functions for `Fix16' are
  804. as follows (corresponding functions are also supported for the others).
  805.  
  806. `Fix16_overflow_saturate'
  807.      The default overflow handler. Results are "saturated": positive
  808.      results are set to the largest representable value (binary
  809.      0.111111...), and negative values to -1.0.
  810.  
  811. `Fix16_ignore'
  812.      Performs no action. For overflow, this will allow addition and
  813.      subtraction operations to "wrap around" in the same manner as
  814.      integer arithmetic, and for saturation, will leave values
  815.      saturated.
  816.  
  817. `Fix16_overflow_warning_saturate'
  818.      Prints a warning message on standard error, then saturates the
  819.      results.
  820.  
  821. `Fix16_warning'
  822.      The default range_error handler. Prints a warning message on
  823.      standard error; otherwise leaving the argument unmodified.
  824.  
  825. `Fix16_abort'
  826.      prints an error message on standard error, then aborts execution.
  827.  
  828.    In addition to arithmetic operations, the following are provided:
  829.  
  830. `Fix16 a = 0.5;'
  831.      Constructs fixed precision objects from double precision values.
  832.      Attempting to initialize to a value outside the range invokes the
  833.      range_error handler, except, as a convenience, initialization to
  834.      1.0 sets the variable to the most positive representable value
  835.      (binary 0.1111111...) without invoking the handler.
  836.  
  837. `short& mantissa(a); long& mantissa(b);'
  838.      return a * pow(2, 15) or b * pow(2, 31) as an integer. These are
  839.      returned by reference, to enable "manual" data manipulation.
  840.  
  841. `double value(a); double value(b);'
  842.      return a or b as floating point numbers.
  843.  
  844. File: libg++.info,  Node: Bit,  Next: Random,  Prev: Fix,  Up: Top
  845.  
  846. Classes for Bit manipulation
  847. ****************************
  848.  
  849.    libg++ provides several different classes supporting the use and
  850. manipulation of collections of bits in different ways.
  851.  
  852.    * Class `Integer' provides "integer" semantics. It supports
  853.      manipulation of bits in ways that are often useful when treating
  854.      bit arrays as numerical (integer) quantities.  This class is
  855.      described elsewhere.
  856.  
  857.    * Class `BitSet' provides "set" semantics. It supports operations
  858.      useful when treating collections of bits as representing
  859.      potentially infinite sets of integers.
  860.  
  861.    * Class `BitSet32' supports fixed-length BitSets holding exactly 32
  862.      bits.
  863.  
  864.    * Class `BitSet256' supports fixed-length BitSets holding exactly
  865.      256 bits.
  866.  
  867.    * Class `BitString' provides "string" (or "vector") semantics.  It
  868.      supports operations useful when treating collections of bits as
  869.      strings of zeros and ones.
  870.  
  871.    These classes also differ in the following ways:
  872.  
  873.    * BitSets are logically infinite. Their space is dynamically altered
  874.      to adjust to the smallest number of consecutive bits actually
  875.      required to represent the sets. Integers also have this property.
  876.      BitStrings are logically finite, but their sizes are internally
  877.      dynamically managed to maintain proper length. This means that,
  878.      for example, BitStrings are concatenatable while BitSets and
  879.      Integers are not.
  880.  
  881.    * BitSet32 and BitSet256 have precisely the same properties as
  882.      BitSets, except that they use constant fixed length bit vectors.
  883.  
  884.    * While all classes support basic unary and binary operations `~, &,
  885.      |, ^, -', the semantics differ. BitSets perform bit operations that
  886.      precisely mirror those for infinite sets. For example,
  887.      complementing an empty BitSet returns one representing an infinite
  888.      number of set bits.  Operations on BitStrings and Integers operate
  889.      only on those bits actually present in the representation.  For
  890.      BitStrings and Integers, the the `&' operation returns a BitString
  891.      with a length equal to the minimum length of the operands, and `|,
  892.      ^' return one with length of the maximum.
  893.  
  894.    * Only BitStrings support substring extraction and bit pattern
  895.      matching.
  896.  
  897. BitSet
  898. ======
  899.  
  900.    BitSets are objects that contain logically infinite sets of
  901. nonnegative integers.  Representational details are discussed in the
  902. Representation chapter. Because they are logically infinite, all
  903. BitSets possess a trailing, infinitely replicated 0 or 1 bit, called
  904. the "virtual bit", and indicated via 0* or 1*.
  905.  
  906.    BitSet32 and BitSet256 have they same properties, except they are of
  907. fixed length, and thus have no virtual bit.
  908.  
  909.    BitSets may be constructed as follows:
  910.  
  911. `BitSet a;'
  912.      declares an empty BitSet.
  913.  
  914. `BitSet a = atoBitSet("001000");'
  915.      sets a to the BitSet 0010*, reading left-to-right. The "0*"
  916.      indicates that the set ends with an infinite number of zero
  917.      (clear) bits.
  918.  
  919. `BitSet a = atoBitSet("00101*");'
  920.      sets a to the BitSet 00101*, where "1*" means that the set ends
  921.      with an infinite number of one (set) bits.
  922.  
  923. `BitSet a = longtoBitSet((long)23);'
  924.      sets a to the BitSet 111010*, the binary representation of decimal
  925.      23.
  926.  
  927. `BitSet a = utoBitSet((unsigned)23);'
  928.      sets a to the BitSet 111010*, the binary representation of decimal
  929.      23.
  930.  
  931.    The following functions and operators are provided (Assume the
  932. declaration of BitSets a = 0011010*, b = 101101*, throughout, as
  933. examples).
  934.  
  935. `~a'
  936.      returns the complement of a, or 1100101* in this case.
  937.  
  938. `a.complement()'
  939.      sets a to ~a.
  940.  
  941. `a & b; a &= b;'
  942.      returns a intersected with b, or 0011010*.
  943.  
  944. `a | b; a |= b;'
  945.      returns a unioned with b, or 1011111*.
  946.  
  947. `a - b; a -= b;'
  948.      returns the set difference of a and b, or 000010*.
  949.  
  950. `a ^ b; a ^= b;'
  951.      returns the symmetric difference of a and b, or 1000101*.
  952.  
  953. `a.empty()'
  954.      returns true if a is an empty set.
  955.  
  956. `a == b;'
  957.      returns true if a and b contain the same set.
  958.  
  959. `a <= b;'
  960.      returns true if a is a subset of b.
  961.  
  962. `a < b;'
  963.      returns true if a is a proper subset of b;
  964.  
  965. `a != b; a >= b; a > b;'
  966.      are the converses of the above.
  967.  
  968. `a.set(7)'
  969.      sets the 7th (counting from 0) bit of a, setting a to 001111010*
  970.  
  971. `a.clear(2)'
  972.      clears the 2nd bit bit of a, setting a to 00011110*
  973.  
  974. `a.clear()'
  975.      clears all bits of a;
  976.  
  977. `a.set()'
  978.      sets all bits of a;
  979.  
  980. `a.invert(0)'
  981.      complements the 0th bit of a, setting a to 10011110*
  982.  
  983. `a.set(0,1)'
  984.      sets the 0th through 1st bits of a, setting a to 110111110* The
  985.      two-argument versions of clear and invert are similar.
  986.  
  987. `a.test(3)'
  988.      returns true if the 3rd bit of a is set.
  989.  
  990. `a.test(3, 5)'
  991.      returns true if any of bits 3 through 5 are set.
  992.  
  993. `int i = a[3]; a[3] = 0;'
  994.      The subscript operator allows bits to be inspected and changed via
  995.      standard subscript semantics, using a friend class BitSetBit.  The
  996.      use of the subscript operator a[i] rather than a.test(i) requires
  997.      somewhat greater overhead.
  998.  
  999. `a.first(1) or a.first()'
  1000.      returns the index of the first set bit of a (2 in this case), or
  1001.      -1 if no bits are set.
  1002.  
  1003. `a.first(0)'
  1004.      returns the index of the first clear bit of a (0 in this case), or
  1005.      -1 if no bits are clear.
  1006.  
  1007. `a.next(2, 1) or a.next(2)'
  1008.      returns the index of the next bit after position 2 that is set (3
  1009.      in this case) or -1. `first' and `next' may be used as iterators,
  1010.      as in `for (int i = a.first(); i >= 0; i = a.next(i))...'.
  1011.  
  1012. `a.last(1)'
  1013.      returns the index of the rightmost set bit, or -1 if there or no
  1014.      set bits or all set bits.
  1015.  
  1016. `a.prev(3, 0)'
  1017.      returns the index of the previous clear bit before position 3.
  1018.  
  1019. `a.count(1)'
  1020.      returns the number of set bits in a, or -1 if there are an
  1021.      infinite number.
  1022.  
  1023. `a.virtual_bit()'
  1024.      returns the trailing (infinitely replicated) bit of a.
  1025.  
  1026. `a = atoBitSet("ababX", 'a', 'b', 'X');'
  1027.      converts the char* string into a bitset, with 'a' denoting false,
  1028.      'b' denoting true, and 'X' denoting infinite replication.
  1029.  
  1030. `a.printon(cout, '-', '.', 0)'
  1031.      prints `a' to `cout' represented with `'-'' for falses, `'.'' for
  1032.      trues, and no replication marker.
  1033.  
  1034. `cout << a'
  1035.      prints `a' to `cout' (representing lases by `'f'', trues by `'t'',
  1036.      and using `'*'' as the replication marker).
  1037.  
  1038. `diff(x, y, z)'
  1039.      A faster way to say z = x - y.
  1040.  
  1041. `and(x, y, z)'
  1042.      A faster way to say z = x & y.
  1043.  
  1044. `or(x, y, z)'
  1045.      A faster way to say z = x | y.
  1046.  
  1047. `xor(x, y, z)'
  1048.      A faster way to say z = x ^ y.
  1049.  
  1050. `complement(x, z)'
  1051.      A faster way to say z = ~x.
  1052.  
  1053. BitString
  1054. =========
  1055.  
  1056.    BitStrings are objects that contain arbitrary-length strings of
  1057. zeroes and ones. BitStrings possess some features that make them behave
  1058. like sets, and others that behave as strings. They are useful in
  1059. applications (such as signature-based algorithms) where both
  1060. capabilities are needed.  Representational details are discussed in the
  1061. Representation chapter.  Most capabilities are exact analogs of those
  1062. supported in the BitSet and String classes.  A BitSubString is used
  1063. with substring operations along the same lines as the String SubString
  1064. class.  A BitPattern class is used for masked bit pattern searching.
  1065.  
  1066.    Only a default constructor is supported.  The declaration `BitString
  1067. a;' initializes a to be an empty BitString.  BitStrings may often be
  1068. initialized via `atoBitString' and `longtoBitString'.
  1069.  
  1070.    Set operations (` ~, complement, &, &=, |, |=, -, ^, ^=') behave
  1071. just as the BitSet versions, except that there is no "virtual bit":
  1072. complementing complements only those bits in the BitString, and all
  1073. binary operations across unequal length BitStrings assume a virtual bit
  1074. of zero. The `&' operation returns a BitString with a length equal to
  1075. the minimum length of the operands, and `|, ^' return one with length
  1076. of the maximum.
  1077.  
  1078.    Set-based relational operations (`==, !=, <=, <, >=, >') follow the
  1079. same rules. A string-like lexicographic comparison function,
  1080. `lcompare', tests the lexicographic relation between two BitStrings.
  1081. For example, lcompare(1100, 0101) returns 1, since the first BitString
  1082. starts with 1 and the second with 0.
  1083.  
  1084.    Individual bit setting, testing, and iterator operations (`set,
  1085. clear, invert, test, first, next, last, prev') are also like those for
  1086. BitSets. BitStrings are automatically expanded when setting bits at
  1087. positions greater than their current length.
  1088.  
  1089.    The string-based capabilities are just as those for class String.
  1090. BitStrings may be concatenated (`+, +='), searched (`index, contains,
  1091. matches'), and extracted into BitSubStrings (`before, at, after') which
  1092. may be assigned and otherwise manipulated. Other string-based utility
  1093. functions (`reverse, common_prefix, common_suffix') are also provided.
  1094. These have the same capabilities and descriptions as those for Strings.
  1095.  
  1096.    String-oriented operations can also be performed with a mask via
  1097. class BitPattern. BitPatterns consist of two BitStrings, a pattern and
  1098. a mask. On searching and matching, bits in the pattern that correspond
  1099. to 0 bits in the mask are ignored. (The mask may be shorter than the
  1100. pattern, in which case trailing mask bits are assumed to be 0). The
  1101. pattern and mask are both public variables, and may be individually
  1102. subjected to other bit operations.
  1103.  
  1104.    Converting to char* and printing (`(atoBitString, atoBitPattern,
  1105. printon, ostream <<)') are also as in BitSets, except that no virtual
  1106. bit is used, and an 'X' in a BitPattern means that the pattern bit is
  1107. masked out.
  1108.  
  1109.    The following features are unique to BitStrings.
  1110.  
  1111.    Assume declarations of BitString a = atoBitString("01010110") and b =
  1112. atoBitSTring("1101").
  1113.  
  1114. `a = b + c;'
  1115.      Sets a to the concatenation of b and c;
  1116.  
  1117. `a = b + 0; a = b + 1;'
  1118.      sets a to b, appended with a zero (one).
  1119.  
  1120. `a += b;'
  1121.      appends b to a;
  1122.  
  1123. `a += 0; a += 1;'
  1124.      appends a zero (one) to a.
  1125.  
  1126. `a << 2; a <<= 2'
  1127.      return a with 2 zeros prepended, setting a to 0001010110. (Note
  1128.      the necessary confusion of << and >> operators. For consistency
  1129.      with the integer versions, << shifts low bits to high, even though
  1130.      they are printed low bits first.)
  1131.  
  1132. `a >> 3; a >>= 3'
  1133.      return a with the first 3 bits deleted, setting a to 10110.
  1134.  
  1135. `a.left_trim(0)'
  1136.      deletes all 0 bits on the left of a, setting a to 1010110.
  1137.  
  1138. `a.right_trim(0)'
  1139.      deletes all trailing 0 bits of a, setting a to 0101011.
  1140.  
  1141. `cat(x, y, z)'
  1142.      A faster way to say z = x + y.
  1143.  
  1144. `diff(x, y, z)'
  1145.      A faster way to say z = x - y.
  1146.  
  1147. `and(x, y, z)'
  1148.      A faster way to say z = x & y.
  1149.  
  1150. `or(x, y, z)'
  1151.      A faster way to say z = x | y.
  1152.  
  1153. `xor(x, y, z)'
  1154.      A faster way to say z = x ^ y.
  1155.  
  1156. `lshift(x, y, z)'
  1157.      A faster way to say z = x << y.
  1158.  
  1159. `rshift(x, y, z)'
  1160.      A faster way to say z = x >> y.
  1161.  
  1162. `complement(x, z)'
  1163.      A faster way to say z = ~x.
  1164.  
  1165. File: libg++.info,  Node: Random,  Next: Data,  Prev: Bit,  Up: Top
  1166.  
  1167. Random Number Generators and related classes
  1168. ********************************************
  1169.  
  1170.    The two classes `RNG' and `Random' are used together to generate a
  1171. variety of random number distributions.  A distinction must be made
  1172. between *random number generators*, implemented by class `RNG', and
  1173. *random number distributions*.  A random number generator produces a
  1174. series of randomly ordered bits.  These bits can be used directly, or
  1175. cast to other representations, such as a floating point value.  A
  1176. random number generator should produce a *uniform* distribution.  A
  1177. random number distribution, on the other hand, uses the randomly
  1178. generated bits of a generator to produce numbers from a distribution
  1179. with specific properties.  Each instance of `Random' uses an instance
  1180. of class `RNG' to provide the raw, uniform distribution used to produce
  1181. the specific distribution.  Several instances of `Random' classes can
  1182. share the same instance of `RNG', or each instance can use its own copy.
  1183.  
  1184. RNG
  1185. ===
  1186.  
  1187.    Random distributions are constructed from members of class `RNG',
  1188. the actual random number generators.  The `RNG' class contains no data;
  1189. it only serves to define the interface to random number generators.
  1190. The `RNG::asLong' member returns an unsigned long (typically 32 bits)
  1191. of random bits.  Applications that require a number of random bits can
  1192. use this directly.  More often, these random bits are transformed to a
  1193. uniform random number:
  1194.  
  1195.          //
  1196.          // Return random bits converted to either a float or a double
  1197.          //
  1198.          float asFloat();
  1199.          double asDouble();
  1200.      };
  1201.  
  1202. using either `asFloat' or `asDouble'.  It is intended that `asFloat'
  1203. and `asDouble' return differing precisions; typically, `asDouble' will
  1204. draw two random longwords and transform them into a legal `double',
  1205. while `asFloat' will draw a single longword and transform it into a
  1206. legal `float'.  These members are used by subclasses of the `Random'
  1207. class to implement a variety of random number distributions.
  1208.  
  1209. ACG
  1210. ===
  1211.  
  1212.    Class `ACG' is a variant of a Linear Congruential Generator
  1213. (Algorithm M) described in Knuth, *Art of Computer Programming, Vol
  1214. III*.  This result is permuted with a Fibonacci Additive Congruential
  1215. Generator to get good independence between samples.  This is a very high
  1216. quality random number generator, although it requires a fair amount of
  1217. memory for each instance of the generator.
  1218.  
  1219.    The `ACG::ACG' constructor takes two parameters: the seed and the
  1220. size.  The seed is any number to be used as an initial seed. The
  1221. performance of the generator depends on having a distribution of bits
  1222. through the seed.  If you choose a number in the range of 0 to 31, a
  1223. seed with more bits is chosen. Other values are deterministically
  1224. modified to give a better distribution of bits.  This provides a good
  1225. random number generator while still allowing a sequence to be repeated
  1226. given the same initial seed.
  1227.  
  1228.    The `size' parameter determines the size of two tables used in the
  1229. generator. The first table is used in the Additive Generator; see the
  1230. algorithm in Knuth for more information. In general, this table is
  1231. `size' longwords long. The default value, used in the algorithm in
  1232. Knuth, gives a table of 220 bytes. The table size affects the period of
  1233. the generators; smaller values give shorter periods and larger tables
  1234. give longer periods. The smallest table size is 7 longwords, and the
  1235. longest is 98 longwords. The `size' parameter also determines the size
  1236. of the table used for the Linear Congruential Generator. This value is
  1237. chosen implicitly based on the size of the Additive Congruential
  1238. Generator table. It is two powers of two larger than the power of two
  1239. that is larger than `size'.  For example, if `size' is 7, the ACG table
  1240. is 7 longwords and the LCG table is 128 longwords. Thus, the default
  1241. size (55) requires 55 + 256 longwords, or 1244 bytes. The largest table
  1242. requires 2440 bytes and the smallest table requires 100 bytes.
  1243. Applications that require a large number of generators or applications
  1244. that aren't so fussy about the quality of the generator may elect to
  1245. use the `MLCG' generator.
  1246.  
  1247. MLCG
  1248. ====
  1249.  
  1250.    The `MLCG' class implements a *Multiplicative Linear Congruential
  1251. Generator*. In particular, it is an implementation of the double MLCG
  1252. described in *"Efficient and Portable Combined Random Number
  1253. Generators"* by Pierre L'Ecuyer, appearing in *Communications of the
  1254. ACM, Vol. 31. No. 6*. This generator has a fairly long period, and has
  1255. been statistically analyzed to show that it gives good inter-sample
  1256. independence.
  1257.  
  1258.    The `MLCG::MLCG' constructor has two parameters, both of which are
  1259. seeds for the generator. As in the `MLCG' generator, both seeds are
  1260. modified to give a "better" distribution of seed digits. Thus, you can
  1261. safely use values such as `0' or `1' for the seeds. The `MLCG'
  1262. generator used much less state than the `ACG' generator; only two
  1263. longwords (8 bytes) are needed for each generator.
  1264.  
  1265. Random
  1266. ======
  1267.  
  1268.    A random number generator may be declared by first declaring a `RNG'
  1269. and then a `Random'. For example, `ACG gen(10, 20); NegativeExpntl rnd
  1270. (1.0, &gen);' declares an additive congruential generator with seed 10
  1271. and table size 20, that is used to generate exponentially distributed
  1272. values with mean of 1.0.
  1273.  
  1274.    The virtual member `Random::operator()' is the common way of
  1275. extracting a random number from a particular distribution.  The base
  1276. class, `Random' does not implement `operator()'. This is performed by
  1277. each of the subclasses. Thus, given the above declaration of `rnd', new
  1278. random values may be obtained via, for example, `double next_exp_rand =
  1279. rnd();' Currently, the following subclasses are provided.
  1280.  
  1281. Binomial
  1282. ========
  1283.  
  1284.    The binomial distribution models successfully drawing items from a
  1285. pool.  The first parameter to the constructor, `n', is the number of
  1286. items in the pool, and the second parameter, `u', is the probability of
  1287. each item being successfully drawn.  The member `asDouble' returns the
  1288. number of samples drawn from the pool.  Although it is not checked, it
  1289. is assumed that `n>0' and `0 <= u <= 1'.  The remaining members allow
  1290. you to read and set the parameters.
  1291.  
  1292. Erlang
  1293. ======
  1294.  
  1295.    The `Erlang' class implements an Erlang distribution with mean
  1296. `mean' and variance `variance'.
  1297.  
  1298. Geometric
  1299. =========
  1300.  
  1301.    The `Geometric' class implements a discrete geometric distribution.
  1302. The first parameter to the constructor, `mean', is the mean of the
  1303. distribution.  Although it is not checked, it is assumed that `0 <=
  1304. mean <= 1'.  `Geometric()' returns the number of uniform random samples
  1305. that were drawn before the sample was larger than `mean'.  This
  1306. quantity is always greater than zero.
  1307.  
  1308. HyperGeometric
  1309. ==============
  1310.  
  1311.    The `HyperGeometric' class implements the hypergeometric
  1312. distribution.  The first parameter to the constructor, `mean', is the
  1313. mean and the second, `variance', is the variance.  The remaining
  1314. members allow you to inspect and change the mean and variance.
  1315.  
  1316. NegativeExpntl
  1317. ==============
  1318.  
  1319.    The `NegativeExpntl' class implements the negative exponential
  1320. distribution.  The first parameter to the constructor is the mean.  The
  1321. remaining members allow you to inspect and change the mean.
  1322.  
  1323. Normal
  1324. ======
  1325.  
  1326.    The `Normal'class implements the normal distribution.  The first
  1327. parameter to the constructor, `mean', is the mean and the second,
  1328. `variance', is the variance.  The remaining members allow you to
  1329. inspect and change the mean and variance.  The `LogNormal' class is a
  1330. subclass of `Normal'.
  1331.  
  1332. LogNormal
  1333. =========
  1334.  
  1335.    The `LogNormal'class implements the logarithmic normal distribution.
  1336. The first parameter to the constructor, `mean', is the mean and the
  1337. second, `variance', is the variance.  The remaining members allow you
  1338. to inspect and change the mean and variance.  The `LogNormal' class is
  1339. a subclass of `Normal'.
  1340.  
  1341. Poisson
  1342. =======
  1343.  
  1344.    The `Poisson' class implements the poisson distribution.  The first
  1345. parameter to the constructor is the mean.  The remaining members allow
  1346. you to inspect and change the mean.
  1347.  
  1348. DiscreteUniform
  1349. ===============
  1350.  
  1351.    The `DiscreteUniform' class implements a uniform random variable over
  1352. the closed interval ranging from `[low..high]'.  The first parameter to
  1353. the constructor is `low', and the second is `high', although the order
  1354. of these may be reversed.  The remaining members allow you to inspect
  1355. and change `low' and `high'.
  1356.  
  1357. Uniform
  1358. =======
  1359.  
  1360.    The `Uniform' class implements a uniform random variable over the
  1361. open interval ranging from `[low..high)'.  The first parameter to the
  1362. constructor is `low', and the second is `high', although the order of
  1363. these may be reversed.  The remaining members allow you to inspect and
  1364. change `low' and `high'.
  1365.  
  1366. Weibull
  1367. =======
  1368.  
  1369.    The `Weibull' class implements a weibull distribution with
  1370. parameters `alpha' and `beta'.  The first parameter to the class
  1371. constructor is `alpha', and the second parameter is `beta'.  The
  1372. remaining members allow you to inspect and change `alpha' and `beta'.
  1373.  
  1374. RandomInteger
  1375. =============
  1376.  
  1377.    The `RandomInteger' class is *not* a subclass of Random, but a
  1378. stand-alone integer-oriented class that is dependent on the RNG
  1379. classes. RandomInteger returns random integers uniformly from the
  1380. closed interval `[low..high]'.  The first parameter to the constructor
  1381. is `low', and the second is `high', although both are optional.  The
  1382. last argument is always a generator.  Additional members allow you to
  1383. inspect and change `low' and `high'.  Random integers are generated
  1384. using `asInt()' or `asLong()'.  Operator syntax (`()') is also
  1385. available as a shorthand for `asLong()'.  Because `RandomInteger' is
  1386. often used in simulations for which uniform random integers are desired
  1387. over a variety of ranges, `asLong()' and `asInt' have `high' as an
  1388. optional argument.  Using this optional argument produces a single
  1389. value from the new range, but does not change the default range.
  1390.  
  1391.